import { DrizzleAdapter } from '@auth/drizzle-adapter';
import NextAuth from 'next-auth';
import Credentials from 'next-auth/providers/credentials';
import GitLab from 'next-auth/providers/gitlab';
import { db } from './server/db/db';

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [
    Credentials({
      name: 'Credentials',
      credentials: {
        username: { label: 'Username' },
        password: { label: 'Password', type: 'password' },
      },

      async authorize(credentials) {
        if (!credentials) return null;

        const { username, password } = credentials;

        if (username !== 'lywq' || password !== 'Lywq@92960314') {
          console.error('credentials', { username, password });
          return null;
        }

        return {
          id: '1',
          credentials,
        };
      },
    }),
    GitLab,
  ],
  adapter: DrizzleAdapter(db),
});
